#include "LinkSerialClient.h"
#include "PacketModbus.h"
#include <iostream>
#include "lib.h"
#include "IMode.h"

using namespace controller;
using namespace std;

void test_modbus(void)
{
    PacketModbus packet_modbus;
    LinkSerialPort l;
    map<string, string> arg = {
        {"dev", "/dev/ttyv0"},
        //{"dev","/dev/ttyS0"},
        {"baud", "115200"}};
    l.open(arg);
    l.set_dump_buffer_type(true);
    packet_modbus.build(0x55, 0x06, 0x1234, 0x02);
    cout << packet_modbus.to_string();

    IMode::S2(&l, (PacketBase *)&packet_modbus, (PacketBase *)&packet_modbus, [&](LinkBase *l, PacketBase *r)
              { 
                cout << "我用对象发送，我真的接收到了一个数据包啦" << endl; 
                cout << "对的，我收到的数据是:"<<r->to_string() <<endl; }, 5000);

    //l.write("kaihua.yang",10);

    IMode::W(&l, &packet_modbus, [&](LinkBase *l, PacketBase *p)
             {
        static int c = 0;
        cout << "第 " << to_string(c) << " 数据包"  << endl;
        c++; }, 10000, 5);

    l.close();
}